package com.itcast.exception;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class GlobalExceptionResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) {
        try {
//            System.out.println("报错:UUID:"+httpServletRequest.getAttribute("UUID")+"\tError Msg:"+e.getMessage());
            httpServletResponse.setHeader("Content-Type","text/html; charset=UTF-8");
            httpServletResponse.getWriter().print("已经进行异常处理");

            httpServletRequest.setAttribute("response","响应体出现异常");
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return null;
    }
}